package services

import (
	"github.com/mlogclub/simple/sqls"
	"github.com/mlogclub/simple/web/params"

	"bbs-go/internal/models"
	"bbs-go/internal/repositories"
)

var IndexCategoryService = newIndexCategoryService()

func newIndexCategoryService() *indexCategoryService {
	return &indexCategoryService{}
}

type indexCategoryService struct {
}

func (s *indexCategoryService) Get(id int64) *models.IndexCategory {
	return repositories.IndexCategoryRepository.Get(sqls.DB(), id)
}

func (s *indexCategoryService) Take(where ...interface{}) *models.IndexCategory {
	return repositories.IndexCategoryRepository.Take(sqls.DB(), where...)
}

func (s *indexCategoryService) Find(cnd *sqls.Cnd) []models.IndexCategory {
	return repositories.IndexCategoryRepository.Find(sqls.DB(), cnd)
}

func (s *indexCategoryService) FindPageByParams(params *params.QueryParams) (list []models.IndexCategory, paging *sqls.Paging) {
	return repositories.IndexCategoryRepository.FindPageByParams(sqls.DB(), params)
}

func (s *indexCategoryService) FindPageByCnd(cnd *sqls.Cnd) (list []models.IndexCategory, paging *sqls.Paging) {
	return repositories.IndexCategoryRepository.FindPageByCnd(sqls.DB(), cnd)
}

func (s *indexCategoryService) Create(t *models.IndexCategory) error {
	return repositories.IndexCategoryRepository.Create(sqls.DB(), t)
}

func (s *indexCategoryService) Update(t *models.IndexCategory) error {
	return repositories.IndexCategoryRepository.Update(sqls.DB(), t)
}

func (s *indexCategoryService) Updates(id int64, columns map[string]interface{}) error {
	return repositories.IndexCategoryRepository.Updates(sqls.DB(), id, columns)
}

func (s *indexCategoryService) UpdateColumn(id int64, name string, value interface{}) error {
	return repositories.IndexCategoryRepository.UpdateColumn(sqls.DB(), id, name, value)
}

func (s *indexCategoryService) GetByName(name string) *models.IndexCategory {
	return repositories.IndexCategoryRepository.GetByName(name)
}

func (s *indexCategoryService) Delete(id int64) error {
	return repositories.IndexCategoryRepository.Delete(sqls.DB(), id)
}
